from PyQt6.QtWidgets import (
    QWidget, QVBoxLayout, QHBoxLayout, QPushButton, QLabel, QLineEdit, 
    QTextEdit, QComboBox, QCheckBox, QRadioButton, QSlider, QProgressBar,
    QListWidget, QGroupBox, QDateEdit, QTimeEdit, QSpinBox, QDoubleSpinBox
)
from PyQt6.QtGui import QIcon, QFont
from PyQt6.QtCore import Qt, QSize, QDate, QTime

class WidgetsTab:
    """基本组件标签页"""
    
    def create_tab(self):
        """创建基本组件标签页"""
        tab = QWidget()
        layout = QVBoxLayout(tab)
        
        # 标题
        title = QLabel("PyQt6 基本组件示例")
        title.setFont(QFont("Arial", 16, QFont.Weight.Bold))
        title.setAlignment(Qt.AlignmentFlag.AlignCenter)
        layout.addWidget(title)
        
        # 使用网格布局组织组件
        grid_layout = QHBoxLayout()
        left_column = QVBoxLayout()
        right_column = QVBoxLayout()
        
        # 左侧列
        # 1. 按钮
        button_group = QGroupBox("按钮")
        button_layout = QVBoxLayout(button_group)
        
        btn1 = QPushButton("普通按钮")
        btn2 = QPushButton("带图标的按钮")
        btn2.setIcon(QIcon("button_icon.png"))  # 替换为实际图标路径
        btn2.setIconSize(QSize(16, 16))
        
        btn3 = QPushButton("禁用按钮")
        btn3.setEnabled(False)
        
        button_layout.addWidget(btn1)
        button_layout.addWidget(btn2)
        button_layout.addWidget(btn3)
        left_column.addWidget(button_group)
        
        # 2. 文本输入
        text_group = QGroupBox("文本输入")
        text_layout = QVBoxLayout(text_group)
        
        line_edit = QLineEdit()
        line_edit.setPlaceholderText("单行文本框...")
        
        text_edit = QTextEdit()
        text_edit.setPlaceholderText("多行文本框...")
        
        text_layout.addWidget(QLabel("单行文本:"))
        text_layout.addWidget(line_edit)
        text_layout.addWidget(QLabel("多行文本:"))
        text_layout.addWidget(text_edit)
        left_column.addWidget(text_group)
        
        # 3. 选择控件
        select_group = QGroupBox("选择控件")
        select_layout = QVBoxLayout(select_group)
        
        combo = QComboBox()
        combo.addItems(["选项1", "选项2", "选项3", "选项4"])
        
        list_widget = QListWidget()
        list_widget.addItems(["列表项1", "列表项2", "列表项3", "列表项4"])
        
        select_layout.addWidget(QLabel("下拉框:"))
        select_layout.addWidget(combo)
        select_layout.addWidget(QLabel("列表框:"))
        select_layout.addWidget(list_widget)
        left_column.addWidget(select_group)
        
        # 右侧列
        # 1. 复选框和单选按钮
        check_radio_group = QGroupBox("复选框和单选按钮")
        check_radio_layout = QVBoxLayout(check_radio_group)
        
        checkbox1 = QCheckBox("复选框 1")
        checkbox2 = QCheckBox("复选框 2 (已选中)")
        checkbox2.setChecked(True)
        
        radio1 = QRadioButton("单选按钮 1")
        radio2 = QRadioButton("单选按钮 2 (已选中)")
        radio2.setChecked(True)
        
        check_radio_layout.addWidget(checkbox1)
        check_radio_layout.addWidget(checkbox2)
        check_radio_layout.addWidget(radio1)
        check_radio_layout.addWidget(radio2)
        right_column.addWidget(check_radio_group)
        
        # 2. 滑块和进度条
        slider_group = QGroupBox("滑块和进度条")
        slider_layout = QVBoxLayout(slider_group)
        
        slider = QSlider(Qt.Orientation.Horizontal)
        slider.setRange(0, 100)
        slider.setValue(50)
        
        progress = QProgressBar()
        progress.setRange(0, 100)
        progress.setValue(75)
        
        slider_layout.addWidget(QLabel("滑块:"))
        slider_layout.addWidget(slider)
        slider_layout.addWidget(QLabel("进度条:"))
        slider_layout.addWidget(progress)
        right_column.addWidget(slider_group)
        
        # 3. 日期和时间
        datetime_group = QGroupBox("日期和时间")
        datetime_layout = QVBoxLayout(datetime_group)
        
        date_edit = QDateEdit()
        date_edit.setDate(QDate.currentDate())
        
        time_edit = QTimeEdit()
        time_edit.setTime(QTime.currentTime())
        
        spinbox = QSpinBox()
        spinbox.setRange(0, 100)
        spinbox.setValue(42)
        
        double_spinbox = QDoubleSpinBox()
        double_spinbox.setRange(0, 10)
        double_spinbox.setValue(3.14)
        double_spinbox.setSingleStep(0.1)
        
        datetime_layout.addWidget(QLabel("日期选择:"))
        datetime_layout.addWidget(date_edit)
        datetime_layout.addWidget(QLabel("时间选择:"))
        datetime_layout.addWidget(time_edit)
        datetime_layout.addWidget(QLabel("整数输入:"))
        datetime_layout.addWidget(spinbox)
        datetime_layout.addWidget(QLabel("浮点数输入:"))
        datetime_layout.addWidget(double_spinbox)
        right_column.addWidget(datetime_group)
        
        # 添加左右列到网格布局
        grid_layout.addLayout(left_column)
        grid_layout.addLayout(right_column)
        layout.addLayout(grid_layout)
        
        return tab